﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace neut
{
    public partial class Log : Form
    {
        public Log()
        {
            InitializeComponent();
        }

        private void Log_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = true;
        }

        static Log dlg;
        public static void Write(string str, bool bShown = false)
        {
            if (dlg == null || dlg.IsDisposed)
            {
                dlg = new Log();
            }
            if (bShown) dlg.Show();

            str = DateTime.Now.ToShortTimeString()+ ">" + str;
            dlg.TextBox.AppendText(str);

            dlg.TextBox.SelectionStart = dlg.TextBox.Text.Length;

            dlg.TextBox.ScrollToCaret();
        }

        public static void Writeline(string str, bool bShown=false)
        {
            if (dlg == null || dlg.IsDisposed)
            {
                dlg = new Log();
            }
            if (bShown) dlg.Show();

            str = DateTime.Now.ToShortTimeString()+">" + str + "\r\n";

            dlg.TextBox.AppendText(str);

            dlg.TextBox.SelectionStart = dlg.TextBox.Text.Length;

            dlg.TextBox.ScrollToCaret();
        }

        public static void ShowWindow()
        {
            if (dlg == null || dlg.IsDisposed)
            {
                dlg = new Log();                
            }

            dlg.Show();
        }
    }
}
